package shipin;

import com.common.model.Video;
import com.jfinal.core.Controller;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;

import java.util.List;

public class VideoCont extends Controller {
    public void add() {
        boolean b = getModel(Video.class, "").save();
        if (b) {
            renderJson("ok");
        } else {
            renderJson("err");
        }
    }

    public void del() {
        boolean b = getModel(Video.class).deleteById(getParaToInt("id"));
        if (b) {
            renderJson("ok");
        } else {
            renderJson("err");
        }
    }

    public void del2() {
        Db.delete("DELETE FROM video WHERE v_type=?",getPara("ty"));
        renderJson("ok");

//        boolean b = getModel(Video.class).deleteById(getParaToInt("id"));
//        if (b) {
//            renderJson("ok");
//        } else {
//            renderJson("err");
//        }
    }



    public void list() {
        String sql = "SELECT * FROM video WHERE v_type=?";
        List<Record> list = Db.find(sql,getPara("type"));
        if (list.size() > 0) {
            renderJson(list);
        } else {
            renderJson("无视频");
        }

    }


}
